package user_wash

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/base-common/headInfo"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/userServiceClient/userrpc"
	"github.com/zeromicro/go-zero/core/logc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserWashDescAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 洗码描述--增加数据
func NewUserWashDescAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserWashDescAddLogic {
	return &UserWashDescAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserWashDescAddLogic) UserWashDescAdd(req *types.UserWashDescAddRequest) (resp *types.UserWashDescAddResponse, err error) {
	id := headInfo.GetTokenUid(l.ctx)
	if id == 0 {
		return nil, code.AdminUserTokenInvalid
	}
	infoResp, err := l.svcCtx.UserServiceRPC.AdminUserInfo(l.ctx, &userrpc.AdminUserInfoRequest{Id: id})
	if err != nil {
		logc.Error(l.ctx, "AdminUserInfo err: ", err)
		return nil, err
	}

	addUserWashDescRequest := &rpc.AddUserWashDescRequest{
		Status:      req.Status,
		AccountId:   infoResp.AdminUser.Id,
		Language:    req.Language,
		Description: req.Description,
	}
	if _, err = l.svcCtx.AssetsRpc.UserWash.AddUserWashDesc(l.ctx, addUserWashDescRequest); err != nil {
		return nil, err
	}
	return &types.UserWashDescAddResponse{}, nil
}
